# -*- coding: utf-8 -*-
# file: encrypt_id.py
# author: JinTian
# time: 13/05/2017 10:04 PM
# Copyright 2017 JinTian. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------------------------------------------------------------
"""
fuck encrypt, I think a simple algorithm is enough
"""
import numpy as np


def encrypt_id(user_id):
    """
    this method encrypt an user_id, return to client, and client will get user information
    using this encrypted id, rather than explode pure id, others have to crack my algorithm
    to get get, or server will return a error.
    :param user_id:
    :return:
    """
    core_code = 15116123160
    encrypted = core_code + 5201314*int(user_id)
    return encrypted


def decrypt_id(encrypt_user_id):
    """
    decrypt to get pure id.
    :param encrypt_user_id:
    :return:
    """
    core_code = 15116123160
    decrypted = (encrypt_user_id - core_code)//5201314
    return decrypted


if __name__ == '__main__':
    r = encrypt_id('2')
    print(r)
    real = decrypt_id(r)
    print(real)